const STORAGE_KEY = 'questionnaire'
const ANSWERS_KEY = 'questionnaire_answers'

export default {
    fetch() {
        return JSON.parse(window.localStorage.getItem(STORAGE_KEY) || '[]')
    },
    save(items) {
        window.localStorage.setItem(STORAGE_KEY, JSON.stringify(items))
    },
    fetchAnswers() {
        return JSON.parse(window.localStorage.getItem(ANSWERS_KEY) || '{}')
    },
    saveAnswer(questionnaireId, answer) {
        const answers = this.fetchAnswers()
        if (!answers[questionnaireId]) {
            answers[questionnaireId] = []
        }
        answers[questionnaireId].push(answer)
        window.localStorage.setItem(ANSWERS_KEY, JSON.stringify(answers))
    }
}
